package LeetCode.month02.day38;

import java.util.Arrays;

public class No167 {
    public static void main(String[] args) {
        System.out.println(Arrays.toString(twoSum(new int[]{2,7,11,15},9)));
    }
    public static int[] twoSum(int[] numbers, int target) {
        int n = numbers.length;
        int left = 0,right = n-1;
        while(true){
            if(numbers[left]+numbers[right]==target){
                return new int[]{left+1,right+1};
            }else if(numbers[left]+numbers[right]<target){
                left++;
            }else{
                right--;
            }
        }
    }
}
